package io.shallwe._admin.basedata.location;


import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;

import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Location;
/**
 * 工艺点信息
 * @author 王小伟
 * @date 2019-06-13 21:46
 */
public class LocationController extends BaseController {

	@Inject LocationService service;
	public void index() {
		render("location.html");
	}
	
	public void list() {
		Integer offset = getParaToInt("offset", 1);
		Integer pageSize = getParaToInt("pageSize", 100);
		String locationCode=get("locationCode");
		String remark=get("remark");
		renderJson(service.paginate(offset, pageSize, locationCode, remark));
	}
	
	public void add() {
		render("add_edit.html");
	}
	
	@Before(LocationValidator.class)
	public void save() {
		Location location=getBean(Location.class,"location");
		renderJson(service.save(location));
	}
	

	public void edit() {
		String id=get("id");
		Location location = service.findById(id);
		set("location",location);
		render("add_edit.html");
	}

	@Before(LocationValidator.class)
	public void update() {
//		Location location= getBean(Location.class,"location");
//		renderJson(service.update(location));
		String id=get("id");
		Integer maxStayTime = getInt("maxStayTime");
		Integer minStayTime = getInt("minStayTime");
		renderJson(service.updateStayTime(id,maxStayTime,minStayTime));
	}
	
	public void delete() {
		String id=get("id");
		renderJson(service.delete(id));
	}

	/**
	 * @Description:   参数为有效
	 * @param:  []
	 * @return: void
	 * @author : gkw
	 */
	public void doControl(){
		String id=get("id");
		renderJson(service.doControl(id));
	}

	/**
	 * @Description:  参数为无效
	 * @param:  []
	 * @return: void
	 * @author : gkw
	 */
	public void notControl(){
		String id=get("id");
		renderJson(service.notControl(id));
	}
}
